package com.aw.guiguzi.adapter

import com.aw.guiguzi.R
import com.aw.guiguzi.bean.NumEncloseBean
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder

class MainResultNumAdapter :
    BaseQuickAdapter<NumEncloseBean, BaseViewHolder>(R.layout.adapter_main_result_num) {
    private var mList: MutableList<NumEncloseBean>? = ArrayList()

    init {
        if (mList == null) {
            mList = ArrayList()
        }
    }

    override fun convert(helper: BaseViewHolder, bean: NumEncloseBean) {
        helper.setText(R.id.tv_num, bean.resultNumber.toString())
        if (bean.isChecked) {
            helper.setBackgroundRes(R.id.tv_num, com.aw.baselib.R.drawable.aw_circle_red)
        } else {
            helper.setBackgroundRes(R.id.tv_num, com.aw.baselib.R.drawable.aw_circle_gray)
        }
    }

    fun addAllData(dataList: MutableList<NumEncloseBean>?) {
        mList = dataList
        setNewData(mList)
        notifyDataSetChanged()
    }

    fun clearData() {
        if (mList != null) {
            val startPosition = 0 //hasHeader is 1
            val preSize = mList!!.size
            if (preSize > 0) {
                mList!!.clear()
                notifyItemRangeRemoved(startPosition, preSize)
            }
        }
    }
}